package com.right.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.right.entity.Foods;
import com.right.entity.Store;
import com.right.service.FoodsService;
import com.right.service.StoreService;
import com.right.service.impl.FoodsServiceImpl;
import com.right.service.impl.StoreServiceImpl;

/**
 * Servlet implementation class MainShowServlet
 */
         
@WebServlet("/MainShowServlet")
public class MainShowServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
  
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	   StoreService ss=new StoreServiceImpl();
	   FoodsService fs=new  FoodsServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		response.getWriter().append("Served at: ").append(request.getContextPath());
		request.setCharacterEncoding("utf-8");
		List<Store> list=	ss.getStroe();
	    list.forEach(System.out::println);
		// 4传递list给jsp
		request.setAttribute("list", list);
		List<Foods> list1=  fs.getFoods("");
		request.setAttribute("list1", list1);
		// 5 转发
		request.getRequestDispatcher("main.jsp").forward(request, response);
	    
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
